﻿/* ***********************************************
 * Author		:  kingthy
 * Email		:  kingthy@gmail.com
 * Description	:  UserProfile
 *
 * ***********************************************/

using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using OpenTwitter.SDK.Http;

namespace OpenTwitter.SDK.Sina.Objects
{
    /// <summary>
    /// 用户的资料数据
    /// </summary>
    public class UserProfile : ResponseObject
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="xml"></param>
        internal UserProfile(XmlNode xml)
            : base(xml)
        { }
        /// <summary>
        /// 用户id
        /// </summary>
        public long Uid { get; private set; }
        /// <summary>
        /// 用户名
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 用户昵称
        /// </summary>
        public string ScreenName { get; private set; }
        /// <summary>
        /// 头像URL
        /// </summary>
        public string Head { get; private set; }
        /// <summary>
        /// 所在地
        /// </summary>
        public string Location { get; private set; }
        /// <summary>
        /// 省份码
        /// </summary>
        public int Province { get; private set; }
        /// <summary>
        /// 城市码
        /// </summary>
        public int City { get; private set; }
        /// <summary>
        /// 描述
        /// </summary>
        public string Description { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public string Url { get; private set; }
        /// <summary>
        /// 
        /// </summary>
        public string Domain { get; private set; }
        /// <summary>
        /// 用户性别
        /// </summary>
        public Gender Gender { get; private set; }
        /// <summary>
        /// 关注人数
        /// </summary>
        public int FollowersCount { get; private set; }
        /// <summary>
        /// 粉丝的人数
        /// </summary>
        public int FriendsCount { get; private set; }
        /// <summary>
        /// 发表的微博数
        /// </summary>
        public int Tweetnum { get; private set; }
        /// <summary>
        /// 收藏数
        /// </summary>
        public int FavouritesCount { get; private set; }
        /// <summary>
        /// 建立时间
        /// </summary>
        public DateTime CreatedAt { get; private set; }
        /// <summary>
        /// 是否已验证的
        /// </summary>
        public bool Verified { get; private set; }
        /// <summary>
        /// 是否关注的
        /// </summary>
        public bool Following { get; private set; }
        /// <summary>
        /// 地理位置是否已开启
        /// </summary>
        public bool GeoEnabled { get; private set; }

        /// <summary>
        /// 
        /// </summary>
        public bool AllowAllActMsg { get; private set; }

        /// <summary>
        /// 最新的一条微博
        /// </summary>
        public Tweet Tweet { get; private set; }

        /// <summary>
        /// 解析XML数据
        /// </summary>
        protected override void Parse()
        {
            this.Name = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("name"));
            this.ScreenName = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("screen_name"));
            this.Uid = Util.GetXmlNodeValue<long>(this.Xml.SelectSingleNode("id"));
            this.Head = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("profile_image_url"));
            this.Location = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("location"));
            this.Province = Util.GetXmlNodeValue<int>(this.Xml.SelectSingleNode("province"));
            this.City = Util.GetXmlNodeValue<int>(this.Xml.SelectSingleNode("city"));
            this.Description = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("description"));
            this.Url = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("url"));
            this.Domain = Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("domain"));
            this.Gender = "m".Equals(Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("gender")), StringComparison.OrdinalIgnoreCase) ? SDK.Gender.Male : SDK.Gender.Female;
            this.FollowersCount = Util.GetXmlNodeValue<int>(this.Xml.SelectSingleNode("followers_count"));
            this.FriendsCount = Util.GetXmlNodeValue<int>(this.Xml.SelectSingleNode("friends_count"));
            this.Tweetnum = Util.GetXmlNodeValue<int>(this.Xml.SelectSingleNode("statuses_count"));
            this.FavouritesCount = Util.GetXmlNodeValue<int>(this.Xml.SelectSingleNode("favourites_count"));
            this.CreatedAt = Util.ConvertSinaTime(Util.GetXmlNodeValue<string>(this.Xml.SelectSingleNode("created_at")));
            this.Following = Util.GetXmlNodeValue<bool>(this.Xml.SelectSingleNode("following"));
            this.Verified = Util.GetXmlNodeValue<bool>(this.Xml.SelectSingleNode("verified"));
            this.GeoEnabled = Util.GetXmlNodeValue<bool>(this.Xml.SelectSingleNode("geo_enabled"));
            this.AllowAllActMsg = Util.GetXmlNodeValue<bool>(this.Xml.SelectSingleNode("allow_all_act_msg"));
            this.Tweet = Util.GetXmlNodeValue<Tweet>(this.Xml.SelectSingleNode("status"));
        }
    }
}
